package dao

import (
	"gitee.com/zhengjianfeng/pay/models"
	"github.com/go-xorm/xorm"
)

type PayAgentDao struct {
	engine *xorm.Engine
}

func NewPayAgentDao(engine *xorm.Engine) *PayAgentDao {
	return &PayAgentDao{
		engine: engine,
	}
}

func (d *PayAgentDao) GetSave(agent *models.PayAgent) (err error) {
	_, err = d.engine.InsertOne(agent)
	return
}

func (d *PayAgentDao) GetAgentRate(agentId int64) (agentRate int, err error) {
	var (
		data *models.PayAgent
		ok   bool
	)
	data = &models.PayAgent{Id: agentId}
	if ok, err = d.engine.Get(data); ok && err == nil {
		return data.AgentRate, err
	} else {
		return 0, err
	}
}
